<template>
  <div class="hyydxq">
    <!-- 生鲜乳交接 -->
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list :immediate-check="false" v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
        <van-cell v-for="(item, index) in list" :key="index" class="approvalItem content" @click='detail(item)'>
          <div class="flex-between font-14 line-height-3">
            <div class="col-333333 font-bold-500 font-15 m-r-10">{{ item.deliveryBatchNo }}</div>
          </div>
          <div class="flex-between font-13 line-height-3">
            <div class="col-666666 m-r-10">交接日期：{{ item.deliveryDate }}</div>
          </div>
          <div class="flex-between font-13 line-height-3">
            <div class="col-666666 m-r-10">生鲜乳总数量（kg）：{{ item.freshMilkTotal }}</div>
          </div>
          <div class="flex-between font-14 line-height-3">
            <div class="col-666666 line-text-out text-right">创建人：{{ item.createdByName }}</div>
            <div class="col-666666 m-r-10 line-text-out">创建时间：{{ item.createTime }}</div>
          </div>
        </van-cell>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
/**
* 生鲜乳交接
**/
import { getValue, setValue } from '@/utils/auth'
import { Toast, Cell, CellGroup, Popup, Picker, DatetimePicker, PullRefresh, CheckboxGroup, List } from 'vant'
import { getHandle } from '@/api'

export default {
  components: {
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Popup.name]: Popup,
    [Picker.name]: Picker,
    [DatetimePicker.name]: DatetimePicker,
    [PullRefresh.name]: PullRefresh,
    [CheckboxGroup.name]: CheckboxGroup,
    [Toast.name]: Toast,
    [List.name]: List
  },
  data() {
    return {
      refreshing: false,
      currentDate: new Date(),
      list: [],
      loading: false,
      finished: false,
      params: {
        page: 1,
        limit: 10,
        tenantCode: getValue('tenantCode'),
        subjectInfoId: getValue('subjectInfoId')
      }
    }
  },
  watch: {},
  created() {},
  mounted() {
    this.$bridge.register('refresh', data => {
      this.refreshing = true
      this.params.page = 1
      this.onLoad()
    })
  },
  methods: {
    // 卡片列表
    onRefresh() {
      this.params.page = 1
      this.finished = false

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.onLoad()
    },
    onSearch() {
      this.params.page = 1
      this.list = []
      this.finished = false

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.onLoad()
    },
    onLoad() {
      getHandle('/agri/api/yzbzh/freshMilkDelivery/queryListPage', this.params).then(res => {
        if (this.refreshing) {
          this.list = []
          this.refreshing = false
        }
        this.list = this.list.concat(res.data.rows)
        this.loading = false

        if (this.list.length >= res.data.count) {
          this.finished = true
        } else {
          this.params.page = this.params.page + 1
        }
      })
    },
    detail(item) {
      setValue('connectId', item.id)
      this.$bridge.call('rawMilkConnectDetail')
    }
  }
}
</script>

<style lang="scss" scoped>
.topCeiling {
  position: fixed;
  top: 0;
  z-index: 1;
}
.topDate {
  width: 80%;
  margin: auto;
  display: flex;
  justify-content: space-between;
  > p {
    font-size: 15px;
    &:first-child {
      width: 40%;
    }
    &:last-child {
      width: 40%;
    }
  }
}
.van-field__control {
  border: 0 !important;
}
.content {
  //   border-bottom: 1px solid #eee;
  padding: 10px 15px;
}
</style>
